package high.concurent.controller;


import high.concurent.request.AddressRequest;
import high.concurent.service.AddressService;
import high.concurrent.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 电商-公司收发货地址表 前端控制器
 * </p>
 *
 * @author 黄保泽
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/api/address/v1/")
@Api(tags = "收货地址模块")
public class AddressController {


    @Autowired
    private AddressService addressService;

    /**
     * 根据地址ID获取地址信息
     * @param addressId 地址ID
     * @return
     */
    @ApiOperation("根据addressId查询收货地址")
    @GetMapping("getAddressById")
    public JsonData getAddressById(@ApiParam(value = "地址id",required = true) @RequestParam(value = "addressId") Long addressId){

        JsonData jsonData = addressService.getAddressById(addressId);
        return jsonData;
    }

    /**
     * 新增收货地址
     * @param addressRequest 地址信息
     * @return
     */
    @ApiOperation("新增收货地址")
    @PostMapping("insertAddress")
    public JsonData insertAddress(@ApiParam(value = "地址信息",required = true) @RequestBody AddressRequest addressRequest){

        JsonData jsonData = addressService.insertAddress(addressRequest);
        return jsonData;
    }


    /**
     * 根据【地址id】与【用户id】删除地址
     * @param addressId 地址id
     * @return
     */
    @ApiOperation("用户地址删除")
    @PostMapping("deleteAddress")
    public JsonData deleteAddress(@ApiParam(value = "地址id",required = true) @RequestParam(value = "addressId") Long addressId){

        JsonData jsonData = addressService.deleteAddress(addressId);
        return jsonData;
    }


    /**
     * 查询用户全部收货地址
     * @return
     */
    @ApiOperation("查询用户全部地址")
    @GetMapping("searchAllAddressList")
    public JsonData searchAllAddressList(){

        JsonData jsonData = addressService.searchAllAddressList();
        return jsonData;
    }
}

